package com.hln.jingwushi.utils

import com.google.gson.Gson
import com.hln.jingwushi.MyApp
import com.hln.jingwushi.bean.VideoMonitoringBean
import com.gdsz.libbasic.utils.file.SharedPreferencesUtils

class VideoInfoCacheUtil {

    companion object {
        const val URL_1 = "url_1_key"
        const val URL_2 = "url_2_key"
        const val URL_3 = "url_3_key"
        const val URL_4 = "url_4_key"
        const val URL_5 = "url_5_key"
        const val URL_6 = "url_6_key"
        const val URL_7 = "url_7_key"
        const val URL_8 = "url_8_key"


        fun setUrl1(videoMonitoringBean: VideoMonitoringBean) {

            SharedPreferencesUtils.setParam(
                MyApp.application(),
                URL_1,
                Gson().toJson(videoMonitoringBean)
            )
        }

        fun getUrl1(): VideoMonitoringBean {
            var str = SharedPreferencesUtils.getParam(
                MyApp.application(),
                URL_1, ""
            )
                ?.toString()
            if (str.isNullOrEmpty()) {
                return VideoMonitoringBean("半球1", "rtsp://admin:hln12345678@192.168.1.160", "1")
            }
            return Gson().fromJson(str, VideoMonitoringBean::class.java)
        }

        fun setUrl2(videoMonitoringBean: VideoMonitoringBean) {

            SharedPreferencesUtils.setParam(
                MyApp.application(),
                URL_2,
                Gson().toJson(videoMonitoringBean)
            )
        }

        fun getUrl2(): VideoMonitoringBean {
            var str = SharedPreferencesUtils.getParam(
                MyApp.application(),
                URL_2, ""
            )
                ?.toString()
            if (str.isNullOrEmpty()) {
                return VideoMonitoringBean("云台1", "rtsp://admin:hln12345678@192.168.1.161", "2")
            }
            return Gson().fromJson(str, VideoMonitoringBean::class.java)
        }

        fun setUrl3(videoMonitoringBean: VideoMonitoringBean) {

            SharedPreferencesUtils.setParam(
                MyApp.application(),
                URL_3,
                Gson().toJson(videoMonitoringBean)
            )
        }

        fun getUrl3(): VideoMonitoringBean {
            var str = SharedPreferencesUtils.getParam(
                MyApp.application(),
                URL_3, ""
            )
                ?.toString()
            if (str.isNullOrEmpty()) {
                return VideoMonitoringBean("枪击1", "rtsp://admin:hln12345678@192.168.1.162", "3")
            }
            return Gson().fromJson(str, VideoMonitoringBean::class.java)
        }

        fun setUrl4(videoMonitoringBean: VideoMonitoringBean) {

            SharedPreferencesUtils.setParam(
                MyApp.application(),
                URL_4,
                Gson().toJson(videoMonitoringBean)
            )
        }

        fun getUrl4(): VideoMonitoringBean {
            var str = SharedPreferencesUtils.getParam(
                MyApp.application(),
                URL_4, ""
            )
                ?.toString()
            if (str.isNullOrEmpty()) {
                return VideoMonitoringBean("球击1", "rtsp://admin:hln12345678@192.168.1.163", "4")
            }
            return Gson().fromJson(str, VideoMonitoringBean::class.java)
        }

        fun setUrl5(videoMonitoringBean: VideoMonitoringBean) {

            SharedPreferencesUtils.setParam(
                MyApp.application(),
                URL_5,
                Gson().toJson(videoMonitoringBean)
            )
        }

        fun getUrl5(): VideoMonitoringBean {
            var str = SharedPreferencesUtils.getParam(
                MyApp.application(),
                URL_5, ""
            )
                ?.toString()
            if (str.isNullOrEmpty()) {
                return VideoMonitoringBean("半球2", "rtsp://admin:hln12345678@192.168.1.164", "5")
            }
            return Gson().fromJson(str, VideoMonitoringBean::class.java)
        }

        fun setUrl6(videoMonitoringBean: VideoMonitoringBean) {

            SharedPreferencesUtils.setParam(
                MyApp.application(),
                URL_6,
                Gson().toJson(videoMonitoringBean)
            )
        }

        fun getUrl6(): VideoMonitoringBean {
            var str = SharedPreferencesUtils.getParam(
                MyApp.application(),
                URL_6, ""
            )
                ?.toString()
            if (str.isNullOrEmpty()) {
                return VideoMonitoringBean("云台2", "rtsp://admin:hln12345678@192.168.1.165", "6")
            }
            return Gson().fromJson(str, VideoMonitoringBean::class.java)
        }

        fun setUrl7(videoMonitoringBean: VideoMonitoringBean) {

            SharedPreferencesUtils.setParam(
                MyApp.application(),
                URL_7,
                Gson().toJson(videoMonitoringBean)
            )
        }

        fun getUrl7(): VideoMonitoringBean {
            var str = SharedPreferencesUtils.getParam(
                MyApp.application(),
                URL_7, ""
            )
                ?.toString()
            if (str.isNullOrEmpty()) {
                return VideoMonitoringBean("枪击2", "rtsp://admin:hln12345678@192.168.1.166", "7")
            }
            return Gson().fromJson(str, VideoMonitoringBean::class.java)
        }

        fun setUrl8(videoMonitoringBean: VideoMonitoringBean) {

            SharedPreferencesUtils.setParam(
                MyApp.application(),
                URL_8,
                Gson().toJson(videoMonitoringBean)
            )
        }

        fun getUrl8(): VideoMonitoringBean {
            var str = SharedPreferencesUtils.getParam(
                MyApp.application(),
                URL_8, ""
            )
                ?.toString()
            if (str.isNullOrEmpty()) {
                return VideoMonitoringBean("球击2", "rtsp://admin:hln12345678@192.168.1.167", "8")
            }
            return Gson().fromJson(str, VideoMonitoringBean::class.java)
        }
    }
}